<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 1. push
// 参数：接收一个或多个参数
// 作用：向指定数组尾部添加元素
// 返回值：新数组的长度
// 例如：
     const BMW = ['X1','X2','X3','X4','X5','IX','X6','X7']
      BMW.push('XM') 
      console.log(BMW) // ['X1','X2','X3','X4','X5','IX','X6','X7','XM']
   
    //2.unshift
    //作用：在数组头部添加一个元素
    const Lamborghini = ['Urus', 'Avantator', 'Huracan','Centenario']
      Lamborghini.unshift('Sian')
      console.log(Lamborghini); //['Sian', 'Urus', 'Avantator', 'Huracan', 'Centenario'] 
      
    //3.pop
    //作用：删除数组最后一个元素
    const Porsche = ['Cayenne', '911', 'Panamera','718']
      Porsche.pop( )
      console.log(Porsche); //['Cayenne', '911', 'Panamera']

    //4.shift  
    //作用：删除数组头部元素
    const Benz = ['GLA', 'GLC', 'GLE','GLS']
    Benz.shift( )
      console.log(Benz); //['GLC', 'GLE', 'GLS']

    //5.splice
    //作用：删除指定元素，并添加元素
    //splice(删除的索引,删除的个数,)
    const Audi = ['A3L', 'A4L', 'A5','A6L','A7','A8']
      Audi.splice(1,2,'RS6')
      console.log(Audi); //['A3L', 'RS6', 'A6L', 'A7', 'A8']
    //6. map()
    //map()不会改变原数组的值，返回一个新数组，新数组中的值为原数组调用函数处理之后的值
    const Ferrari = ['458','488pista','Roma','f8','812','Portofino','SF-90','296GTB']
    const newFerrari = Ferrari.map(function (item,index){
      return item
    })
    console.log(newFerrari);//['458','488pista','Roma','f8','812','Portofino','SF-90','296GTB']

    //7.forEach()
    //用于遍历数组的方法,将遍历到的元素传递给回调函数，遍历的数组不能是空
    const mclaren = ['570s','720s','765LT','Artura']
     BMW.forEach(function(newMclaren){
       console.log(newMclaren);
    })

    //8.includes
    //用于检查数组中是否包含特定元素
    const AstonMartin = ['DBS','DB11','DBX','Vantage']
    const newAstonMartin = AstonMartin.includes('DB11')
    console.log(newAstonMartin);//true
  </script>
</body>
</html>